package pl.edu.agh.utils;

public class EMA {
    private static final double ALPHA = 0.2;
    private Double oldValue;


    public double getEMA(double[] values){
        double emaValue = 0.0;

        for(double value: values){
            emaValue = average(value);
        }

        return emaValue;
    }

    private double average(double value) {
        if (oldValue == null) {
            oldValue = value;
            return value;
        }

        double newValue = oldValue + ALPHA * (value - oldValue);
        oldValue = newValue;
        return newValue;
    }
}
